package main

import "fmt"

func main() {
	s0 := []int{10, 30, 50, 70, 90, 110, 120, 130}
	s1 := make([]int, 3)
	n := copy(s1, s0)
	fmt.Printf("s0 %p, %p, l=%-2d, c=%-2d, %v \n", &s0, &s0[0], len(s0), cap(s0), s0)

	fmt.Printf("s1 %p, %p, l=%-2d, c=%-2d, %v \n", &s1, &s1[0], len(s1), cap(s1), s1)
	fmt.Println(n)

	// s2 := make([]int, 0)
	// copy(s2, s0)

	// var s2 []int //?
	// copy(s2, s0)
	// fmt.Printf("s2 %p, %p, l=%-2d, c=%-2d, %v \n", &s2, &s2[0], len(s2), cap(s2), s2)
	// fmt.Println(s2)

	s2 := make([]int, 1)
	copy(s2, s0)
	fmt.Printf("s2 %p, %p, l=%-2d, c=%-2d, %v \n", &s2, &s2[0], len(s2), cap(s2), s2)

	copy(s2, s0[2:])
	fmt.Printf("s2 %p, %p, l=%-2d, c=%-2d, %v \n", &s2, &s2[0], len(s2), cap(s2), s2)

	// 合并 1 不能再现有切片上合并，底层数组不能扩容

	s3 := make([]int, len(s1)+len(s2)) // len=4 cap=4
	copy(s3, s1)
	fmt.Printf("s3 %p, %p, l=%-2d, c=%-2d, %v \n", &s3, &s3[0], len(s3), cap(s3), s3)
	copy(s3, s2)
	fmt.Printf("s3 %p, %p, l=%-2d, c=%-2d, %v \n", &s3, &s3[0], len(s3), cap(s3), s3)
	copy(s3[3:], s2)
	fmt.Printf("s3 %p, %p, l=%-2d, c=%-2d, %v \n", &s3, &s3[0], len(s3), cap(s3), s3)

	// 合并 2
	s4 := make([]int, 0, len(s1)+len(s2)) // len=0, cap=4[]
	s4 = append(s4, s1...)
	fmt.Printf("s4 %p, %p, l=%-2d, c=%-2d, %v \n", &s4, &s4[0], len(s4), cap(s4), s4)

	// delete
	var s5 []int
	s5 = append(s5, s0[:2]...)
	fmt.Printf("s5 %p, %p, l=%-2d, c=%-2d, %v \n", &s5, &s5[0], len(s5), cap(s5), s5)
	s5 = append(s5, s0[len(s0)-2:]...)
	fmt.Printf("s5 %p, %p, l=%-2d, c=%-2d, %v \n", &s5, &s5[0], len(s5), cap(s5), s5)

}
